package com.oa.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.oa.bean.Log;
import com.oa.dao.LogDao;
import com.oa.service.LogService;

@Service
public class LogServiceImpl implements LogService{

	@Autowired
	LogDao logDao;
	
	
	@Override
	public String addLog(Log log) {
		// TODO Auto-generated method stub
		Integer result = logDao.insertLog(log);
		if(result!=0){
			return "true";
		}
		return "false";
	}


	@Override
	public Map<String, Object> getLogList(Map<String, Object> map) {
		// TODO Auto-generated method stub
		Page page=PageHelper.startPage((Integer)map.get("currentPage"), 6,"log.logid desc");
		
		List<Log> list = logDao.selectLogByMap(map);
		Map<String,Object> result = new HashMap<>();
		result.put("logList", list);
		result.put("mixNum", page.getPages());
		result.put("limit", 6);
		return result;
	}


	@Override
	public String deleletLogs(String str) {
		// TODO Auto-generated method stub
		System.out.println(str);
		String[]arr=str.split(",");
		int[]array = new int[2];
		for(int i=0;i<arr.length;i++){
			array[i]=Integer.parseInt(arr[i]);
		}
		Integer result = logDao.deleteLogByArray(array);
		if(result!=0){
			return "true";
		}
		return "false";
	}

	
}
